package com.liuzhilong.infrastructure.basic.factory.statics.factory.auto;

import com.liuzhilong.infrastructure.basic.factory.statics.factory.Product;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

public class AutoFactory {
    private static final Map<String, Supplier<Product>> FACTORY_METHOD_HOLDER = new HashMap<>();

    public static final void registerProduct(String productKey,Supplier<Product> factoryMethod){
        FACTORY_METHOD_HOLDER.put(productKey,factoryMethod);
    }

    public static final Product getProduct(String productKey){
        if(!FACTORY_METHOD_HOLDER.containsKey(productKey)){
            throw new IllegalArgumentException("为实现的方法["+productKey+"]");
        }
        return FACTORY_METHOD_HOLDER.get(productKey).get();
    }





}
